﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PluginInterface;
using Buccontrols;
using System.Drawing;
using System.Windows.Forms;

namespace Buccaneer
{
    class LoadRescImgAction : PluginAction
    {
        public LoadRescImgAction()
        {
            base.name = "loadrescimg";
            base.func = new ActionFunction(LoadRescImage);
            base.pars.Add("reason", "the reason for the application to exit");
        }

        public static void LoadRescImage(string[] args)
        {
            if (args == null || args.Length < 2 || args[1] == "")
            {
                Options.WriteComment("(!) Please parse 2 parameters, namely:");
                Options.WriteComment(" -  name of the image to be used later on");
                Options.WriteComment(" -  path of the file to be loaded");
                return;
            }
            Options.LoadImage(args[0], args[1]);
        }
    }

    class ShowRescImgAction : PluginAction
    {
        public ShowRescImgAction()
        {
            base.name = "showrescimg";
            base.func = new ActionFunction(ShowRescImage);
            base.pars.Add("name", "The name of the image resource");
            base.exceptions.Add("System.InvalidOperationException", new ActionFunction(ShowRescImageThreadSafe));
        }

        public static void ShowRescImage(string[] args)
        {
            Image img = Options.GetResource(args[0]) as Image;
            PluginForm frm = new PluginForm();
                frm.MdiParent = MainProgram.MainForm;
                frm.Name = "PluginForm" + MainProgram.MainForm.MdiChildren.Length.ToString();
                frm.Size = img.Size;

            Label lbl = new Label();
                lbl.AutoSize = false;
                lbl.Dock = DockStyle.Fill;
                lbl.BackgroundImage = img;

                frm.Controls.Add(lbl);
                frm.Show();
        }

        public static void ShowRescImageThreadSafe(string[] args)
        {
            MainProgram.MainForm.ActRequest("showrescimg", args);
        }
    }
}
